package com.cheyun.netsalev3.view

import android.text.InputType
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.cheyun.netsalev3.MyApplication
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.databinding.ActivityLoginBinding
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.utils.FunctionUtils
import com.cheyun.netsalev3.viewmodel.LoginActivityViewModel
import com.cheyun.netsalev3.widget.floatingview.FloatingView


class LoginActivity : BaseActivity<ActivityLoginBinding>() {
    override fun initViewModel(): ViewModel? {
        return ViewModelProviders.of(this).get(LoginActivityViewModel::class.java)
    }

    override fun initContentView(): Int {
        return R.layout.activity_login
    }

    override fun initView() {
        binding.viewModel?.version ="v"+ FunctionUtils.getCurrentVersion(this);
        binding.viewModel?.activity = this
        binding.viewModel?.showPwd?.postValue(false)

//        FloatActionController.getInstance().hide()
        FloatingView.get().remove();
        MyApplication.getInstance().enableShowMsg = false
    }

    override fun initData() {
//        MyApplication.getInstance().initAcitvitys(LoginActivity::class.java)

        binding.viewModel?.showPwd?.observe(this, Observer { it ->
            val img = resources.getDrawable(if(it){R.drawable.mmxs_tb}else{R.drawable.yincangmima})
            binding.ivPwd.setImageDrawable(img)
            binding.etPwd.inputType = if(it) InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_NORMAL else InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
        })
    }

}
